<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="kalip" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{kalipHome.managed ? 'Edit' : 'Add'} Kalip</f:facet>

			<rich:layout>
              	<rich:layoutPanel position="left" id="ilkKontrol">
		            <s:decorate id="kodField" template="layout/edit.xhtml">
		                <ui:define name="label">Kod</ui:define>
		                <h:inputText id="kod" cols="80" rows="3" required="true" value="#{kalipHome.instance.kod}"/>
		            </s:decorate>
		            
		            <s:decorate id="adField" template="layout/edit.xhtml">
		                <ui:define name="label">Ad</ui:define>
		                <h:inputText id="ad" cols="80" rows="10" required="true" value="#{kalipHome.instance.ad}"/>
		            </s:decorate>
		
		            <s:decorate id="agirlikField" template="layout/edit.xhtml">
		                <ui:define name="label">Agirlik</ui:define>
		                <h:inputText id="agirlik" value="#{kalipHome.instance.agirlik}">
		                    <a:support event="onblur" reRender="agirlikField" bypassUpdates="true" ajaxSingle="true"/>
		                </h:inputText>
		            </s:decorate>
		
		            <s:decorate id="grupField" template="layout/edit.xhtml">
		                <ui:define name="label">Ölçü Birimi</ui:define>
				      	<h:selectOneMenu  width="250" value="#{kalipHome.instance.olcubirim}">
							<s:selectItems value="#{olcubirimList.resultList}" var="ind" label="#{ind.kisaad} - #{ind.ad}" noSelectionLabel="Seçim Yapınız!"  />
							<s:convertEntity />
						</h:selectOneMenu>
					</s:decorate>
			
		            <s:decorate id="setmiField" template="layout/edit.xhtml">
		                <ui:define name="label">Setmi</ui:define>
		                <a:region>
			                <h:selectBooleanCheckbox id="setmi" required="true" value="#{kalipHome.instance.setmi}">
			                	<a:support event="onclick" reRender="alkKalipLayout" />
			                </h:selectBooleanCheckbox>
		                </a:region>
		            </s:decorate>
		    	</rich:layoutPanel>
		    	
				<rich:layoutPanel position="center">
					<a:outputPanel ajaxRendered="true">
						<h:panelGroup id="alkKalipLayout" rendered="#{kalipHome.instance.setmi}">
					 		<s:decorate id="grupField2" template="layout/edit.xhtml">
				                <ui:define name="label">Alt Kalıp</ui:define>
						      	<h:selectOneMenu  width="250" value="#{kalipHome.selectedAltKalip}" rendered="#{kalipHome.instance.setmi}">
									<s:selectItems value="#{kalipList.resultList}" var="ind" label="#{ind.kod} - #{ind.ad}" noSelectionLabel="Seçim Yapınız!"  />
									<s:convertEntity />
								</h:selectOneMenu>
							</s:decorate>
							
							
				            <s:decorate id="altkalipadetField" template="layout/edit.xhtml">
				                <ui:define name="label">Alt Kalıp Adeti</ui:define>
				                <h:inputText id="altkalipadet" value="#{kalipHome.altKalipAdet}">
				                    <a:support event="onblur" reRender="altkalipadetField" bypassUpdates="true" ajaxSingle="true"/>
				                </h:inputText>
				            </s:decorate>
							
							<s:decorate id="altkalipEkle" template="layout/edit.xhtml"  style="align: right;">
								<h:commandButton id="altKalipEkleButton" value="   Alt Kalıp Ekle   " action="#{kalipHome.addAltKalip()}" />
							</s:decorate>
							
							<s:decorate id="altkalipLabel" template="layout/edit.xhtml">
								<s:label></s:label>
							</s:decorate>
							
							<s:div style=" width : 360px;">
								<h:panelGrid columnClasses="acent" width="360">
									<rich:datascroller for="kalipAltKalipListTable" maxPages="5" />
									<rich:dataTable value="#{kalipHome.kalipAltKalipList}" var="_kalipaltkalip" 
				                      rowClasses="rvgRowOne,rvgRowTwo" id="kalipAltKalipListTable" rows="5">
						                <rich:column sortBy="#{_kalipaltkalip.altKalip.ad}" width="60%">
						                    <f:facet name="header">Alt Kalıp</f:facet>
						                    <h:outputText value="#{_kalipaltkalip.altKalip.ad}"/>
						                </rich:column>
						                
						                <rich:column sortBy="#{_kalipaltkalip.altkalipadet}" width="40%">
						                    <f:facet name="header">Alt Kalıp Adet</f:facet>
						                    <h:outputText value="#{_kalipaltkalip.altkalipadet}"/>
						                </rich:column>
						                
						                <rich:column>
						                	<h:commandButton id="deleteAltKalip" value="Sil" action="#{kalipHome.removeAltKalip(_kalipaltkalip)}" />
						                </rich:column>
						            </rich:dataTable>
						        </h:panelGrid>
							</s:div>
	
						</h:panelGroup>
					</a:outputPanel>
				</rich:layoutPanel>
			</rich:layout>
            
        <div style="clear:both">
            <span class="required">*</span>
            required fields
        </div>

        </rich:panel>

        <div class="actionButtons">
            <h:commandButton id="save" value="Save" action="#{kalipHome.persist}" disabled="#{!kalipHome.wired}" rendered="#{!kalipHome.managed}"/>
            <h:commandButton id="update" value="Save" action="#{kalipHome.update}" rendered="#{kalipHome.managed}"/>
            <h:commandButton id="delete" value="Delete" action="#{kalipHome.remove}" immediate="true" rendered="#{kalipHome.managed}"  />
            <s:button id="cancelEdit" value="Cancel" propagation="end" view="/Kalip.xhtml" rendered="#{kalipHome.managed}"/>
            <s:button id="cancelAdd" value="Cancel" propagation="end" view="/#{empty kalipFrom ? 'KalipList' : kalipFrom}.xhtml" rendered="#{!kalipHome.managed}"/>
        </div>
        
    </h:form>

<rich:tabPanel switchType="ajax" rendered="#{kalipHome.instance.firma == null || authenticator.isAdmin()}">

    <rich:tab label="Firma *" labelClass="required">
    <div class="association" id="firmaParent">

        <h:outputText value="There is no firma associated with this kalip."
                   rendered="#{kalipHome.instance.firma == null}"/>

        <rich:dataTable var="_firma"
                   value="#{kalipHome.instance.firma}"
                rendered="#{kalipHome.instance.firma != null}"
              rowClasses="rvgRowOne,rvgRowTwo"
                      id="firmaTable">
            <h:column>
                <f:facet name="header">Id</f:facet>
                <h:outputText value="#{_firma.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Ad</f:facet>
                <h:outputText value="#{_firma.ad}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Adres</f:facet>
                <h:outputText value="#{_firma.adres}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Eposta</f:facet>
                <h:outputText value="#{_firma.eposta}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Kod</f:facet>
                <h:outputText value="#{_firma.kod}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Mersisno</f:facet>
                <h:outputText value="#{_firma.mersisno}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Telefon</f:facet>
                <h:outputText value="#{_firma.telefon}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Vergino</f:facet>
                <h:outputText value="#{_firma.vergino}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Webadresi</f:facet>
                <h:outputText value="#{_firma.webadresi}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{kalipHome.instance.firma != null ? 'changeParent' : 'selectParent'}" value="#{kalipHome.instance.firma != null ? 'Change' : 'Select'} firma"
                       view="/FirmaList.xhtml">
                <f:param name="from" value="KalipEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>
    
</rich:tabPanel>
</ui:define>

</ui:composition>
